<template>
	<div class="layout-padding">
		<div class="layout-padding-auto layout-padding-view">
			<el-row class="ml10" v-show="showSearch">
				<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList" ref="queryRef">
					<el-form-item :label="$t('customer.customerName')" prop="customerName">
						<el-input :placeholder="$t('customer.inputCustomerNameTip')" style="max-width: 180px" v-model="state.queryForm.customerName" />
					</el-form-item>
          <el-form-item v-auth="'sys_customer_filter'" :label="$t('customer.contact')" prop="contact">
            <el-input :placeholder="$t('customer.inputContactTip')" style="max-width: 180px" v-model="state.queryForm.contact" />
          </el-form-item>
          <el-form-item v-auth="'sys_customer_filter'" :label="$t('sysuser.username')" prop="createBy">
            <el-select class="w100" clearable  :placeholder="t('customer.inputSelectTip')" v-model="state.queryForm.createBy">
              <el-option :key="item.username" :label="item.name" :value="item.username" v-for="item in userData"/>
            </el-select>
          </el-form-item>
					<el-form-item>
						<el-button @click="getDataList" icon="search" type="primary">
							{{ $t('common.queryBtn') }}
						</el-button>
						<el-button @click="resetQuery" icon="Refresh">{{ $t('common.resetBtn') }}</el-button>
					</el-form-item>
				</el-form>
			</el-row>
			<el-table
				:data="state.dataList"
				style="width: 100%"
				v-loading="state.loading"
				border
				:cell-style="tableStyle?.cellStyle"
				:header-cell-style="tableStyle?.headerCellStyle"
			>
				<el-table-column align="center" type="selection" width="40" />
				<el-table-column :label="t('customer.index')" type="index" width="60" />
        <el-table-column :label="t('customer.customerName')" prop="customerName" show-overflow-tooltip />
        <el-table-column :label="t('customer.contact')" prop="contact" show-overflow-tooltip />
        <el-table-column :label="t('customer.customerAddress')" prop="customerAddress" show-overflow-tooltip />
        <el-table-column :label="t('customer.customerPhone')" prop="customerPhone" show-overflow-tooltip />
        <el-table-column :label="t('customer.remark')" prop="remark" show-overflow-tooltip />
        <el-table-column :label="t('customer.createBy')" prop="createBy" show-overflow-tooltip />
        <el-table-column :label="t('customer.createTime')" prop="createTime" show-overflow-tooltip />
			</el-table>
			<pagination @current-change="currentChangeHandle" @size-change="sizeChangeHandle" v-bind="state.pagination" />
		</div>
	</div>
</template>

<script lang="ts" name="customer" setup>
import { BasicTableProps, useTable } from '/@/hooks/table';
import { fetchHistoryList,userList } from '/@/api/bcp/customer';
import { useMessage, useMessageBox } from '/@/hooks/message';
import { useI18n } from 'vue-i18n';

const { t } = useI18n();

// 定义变量内容
const formDialogRef = ref();
// 搜索变量
const queryRef = ref();
const showSearch = ref(true);
//用户姓名
const userData = ref([]) as any;

const state: BasicTableProps = reactive<BasicTableProps>({
	queryForm: {},
	pageList: fetchHistoryList,
});

//  table hook
const { getDataList, currentChangeHandle, sizeChangeHandle, downBlobFile, tableStyle } = useTable(state);

// 清空搜索条件
const resetQuery = () => {
	queryRef.value.resetFields();
	getDataList();
};
// 用户数据
const getUserData = () => {
  userList({current: 1, size: 100}).then((res) => {
    userData.value = res.data.records.filter(function(user:any) {
      return user.username !== 'admin';
    });
  });
};
// 获取用户数据
getUserData()
</script>
